﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ServiceProcess;

namespace SharepointSolutionInstaller.Utils.RequiredChecks
{
    /// <summary>
    /// Checks if the Windows SharePoint Services Administration service is started.
    /// </summary>
    internal class AdminServiceCheck : SystemCheck
    {
        internal AdminServiceCheck() : base("AdminServiceCheck") { }

        protected override SystemCheckResult DoExecute()
        {
            try
            {
                ServiceController sc = new ServiceController("SPAdminV4");
                if (sc.Status == ServiceControllerStatus.Running)
                {
                    return SystemCheckResult.Success;
                }
                return SystemCheckResult.Error;
            }

            catch (Win32Exception ex)
            {
               
            }

            catch (InvalidOperationException ex)
            {
              
            }

            return SystemCheckResult.Inconclusive;
        }

        protected override bool CanRun
        {
            get { return IsWSSInstalled; }
        }
    }
}
